package com.github.postsanf.yinian.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.KeyEventCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewConfigurationCompat;
import android.util.AttributeSet;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.Scroller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class MyCustomViewAbove extends ViewGroup {
    private static final String TAG = "CustomViewAbove";
    private static final boolean DEBUG = false;
    private static final boolean USE_CACHE = false;
    private static final int MAX_SETTLE_DURATION = 600;
    private static final int MIN_DISTANCE_FOR_FLING = 25;
    private static final Interpolator sInterpolator = new Interpolator() {
        public float getInterpolation(float t) {
            --t;
            return t * t * t * t * t + 1.0F;
        }
    };
    private View mContent;
    private int mCurItem;
    private Scroller mScroller;
    private boolean mScrollingCacheEnabled;
    private boolean mScrolling;
    private boolean mIsBeingDragged;
    private boolean mIsUnableToDrag;
    private int mTouchSlop;
    private float mInitialMotionX;
    private float mLastMotionX;
    private float mLastMotionY;
    protected int mActivePointerId;
    private static final int INVALID_POINTER = -1;
    protected VelocityTracker mVelocityTracker;
    private int mMinimumVelocity;
    protected int mMaximumVelocity;
    private int mFlingDistance;
    private MyCustomViewBehind mViewBehind;
    private boolean mEnabled;
    private MyCustomViewAbove.OnPageChangeListener mOnPageChangeListener;
    private MyCustomViewAbove.OnPageChangeListener mInternalPageChangeListener;
    private MySlidingMenu.OnClosedListener mClosedListener;
    private MySlidingMenu.OnOpenedListener mOpenedListener;
    private List<View> mIgnoredViews;
    protected int mTouchMode;
    private boolean mQuickReturn;
    private float mScrollX;

    public MyCustomViewAbove(Context context) {
        this(context, (AttributeSet) null);
    }

    public MyCustomViewAbove(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mActivePointerId = -1;
        this.mEnabled = true;
        this.mIgnoredViews = new ArrayList();
        this.mTouchMode = 0;
        this.mQuickReturn = false;
        this.mScrollX = 0.0F;
        this.initCustomViewAbove();
    }

    void initCustomViewAbove() {
        this.setWillNotDraw(false);
        this.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        this.setFocusable(true);
        Context context = this.getContext();
        this.mScroller = new Scroller(context, sInterpolator);
        ViewConfiguration configuration = ViewConfiguration.get(context);
        this.mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
        this.mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
        this.mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
        this.setInternalPageChangeListener(new MyCustomViewAbove.SimpleOnPageChangeListener() {
            public void onPageSelected(int position) {
                if (mViewBehind != null) {
                    switch (position) {
                        case 0:
                        case 2:
                            mViewBehind.setChildrenEnabled(true);
                            break;
                        case 1:
                            mViewBehind.setChildrenEnabled(false);
                    }
                }

            }
        });
        float density = context.getResources().getDisplayMetrics().density;
        this.mFlingDistance = (int) (25.0F * density);
    }

    public void setCurrentItem(int item) {
        this.setCurrentItemInternal(item, true, false);
    }

    public void setCurrentItem(int item, boolean smoothScroll) {
        this.setCurrentItemInternal(item, smoothScroll, false);
    }

    public int getCurrentItem() {
        return this.mCurItem;
    }

    void setCurrentItemInternal(int item, boolean smoothScroll, boolean always) {
        this.setCurrentItemInternal(item, smoothScroll, always, 0);
    }

    void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
        if (!always && this.mCurItem == item) {
            this.setScrollingCacheEnabled(false);
        } else {
            item = this.mViewBehind.getMenuPage(item);
            boolean dispatchSelected = this.mCurItem != item;
            this.mCurItem = item;
            int destX = this.getDestScrollX(this.mCurItem);
            if (dispatchSelected && this.mOnPageChangeListener != null) {
                this.mOnPageChangeListener.onPageSelected(item);
            }

            if (dispatchSelected && this.mInternalPageChangeListener != null) {
                this.mInternalPageChangeListener.onPageSelected(item);
            }

            if (smoothScroll) {
                this.smoothScrollTo(destX, 0, velocity);
            } else {
                this.completeScroll();
                this.scrollTo(destX, 0);
            }

        }
    }

    public void setOnPageChangeListener(MyCustomViewAbove.OnPageChangeListener listener) {
        this.mOnPageChangeListener = listener;
    }

    public void setOnOpenedListener(MySlidingMenu.OnOpenedListener l) {
        this.mOpenedListener = l;
    }

    public void setOnClosedListener(MySlidingMenu.OnClosedListener l) {
        this.mClosedListener = l;
    }

    MyCustomViewAbove.OnPageChangeListener setInternalPageChangeListener(MyCustomViewAbove.OnPageChangeListener listener) {
        MyCustomViewAbove.OnPageChangeListener oldListener = this.mInternalPageChangeListener;
        this.mInternalPageChangeListener = listener;
        return oldListener;
    }

    public void addIgnoredView(View v) {
        if (!this.mIgnoredViews.contains(v)) {
            this.mIgnoredViews.add(v);
        }

    }

    public void removeIgnoredView(View v) {
        this.mIgnoredViews.remove(v);
    }

    public void clearIgnoredViews() {
        this.mIgnoredViews.clear();
    }

    float distanceInfluenceForSnapDuration(float f) {
        f -= 0.5F;
        f = (float) ((double) f * 0.4712389167638204D);
        return (float) Math.sin(f);
    }

    public int getDestScrollX(int page) {
        switch (page) {
            case 0:
            case 2:
                return this.mViewBehind.getMenuLeft(this.mContent, page);
            case 1:
                return this.mContent.getLeft();
            default:
                return 0;
        }
    }

    private int getLeftBound() {
        return this.mViewBehind.getAbsLeftBound(this.mContent);
    }

    private int getRightBound() {
        return this.mViewBehind.getAbsRightBound(this.mContent);
    }

    public int getContentLeft() {
        return this.mContent.getLeft() + this.mContent.getPaddingLeft();
    }

    public boolean isMenuOpen() {
        return this.mCurItem == 0 || this.mCurItem == 2;
    }

    private boolean isInIgnoredView(MotionEvent ev) {
        Rect rect = new Rect();
        Iterator var4 = this.mIgnoredViews.iterator();

        while (var4.hasNext()) {
            View v = (View) var4.next();
            v.getHitRect(rect);
            if (rect.contains((int) ev.getX(), (int) ev.getY())) {
                return true;
            }
        }

        return false;
    }

    public int getBehindWidth() {
        return this.mViewBehind == null ? 0 : this.mViewBehind.getBehindWidth();
    }

    public int getChildWidth(int i) {
        switch (i) {
            case 0:
                return this.getBehindWidth();
            case 1:
                return this.mContent.getWidth();
            default:
                return 0;
        }
    }

    public boolean isSlidingEnabled() {
        return this.mEnabled;
    }

    public void setSlidingEnabled(boolean b) {
        this.mEnabled = b;
    }

    void smoothScrollTo(int x, int y) {
        this.smoothScrollTo(x, y, 0);
    }

    void smoothScrollTo(int x, int y, int velocity) {
        if (this.getChildCount() == 0) {
            this.setScrollingCacheEnabled(false);
        } else {
            int sx = this.getScrollX();
            int sy = this.getScrollY();
            int dx = x - sx;
            int dy = y - sy;
            if (dx == 0 && dy == 0) {
                this.completeScroll();
                if (this.isMenuOpen()) {
                    if (this.mOpenedListener != null) {
                        this.mOpenedListener.onOpened();
                    }
                } else if (this.mClosedListener != null) {
                    this.mClosedListener.onClosed();
                }

            } else {
                this.setScrollingCacheEnabled(true);
                this.mScrolling = true;
                int width = this.getBehindWidth();
                int halfWidth = width / 2;
                float distanceRatio = Math.min(1.0F, 1.0F * (float) Math.abs(dx) / (float) width);
                float distance = (float) halfWidth + (float) halfWidth * this.distanceInfluenceForSnapDuration(distanceRatio);
                boolean duration = false;
                velocity = Math.abs(velocity);
                int duration1;
                if (velocity > 0) {
                    duration1 = 4 * Math.round(1000.0F * Math.abs(distance / (float) velocity));
                } else {
                    float pageDelta = (float) Math.abs(dx) / (float) width;
                    duration1 = (int) ((pageDelta + 1.0F) * 100.0F);
                    duration1 = 600;
                }

                duration1 = Math.min(duration1, 600);
                this.mScroller.startScroll(sx, sy, dx, dy, duration1);
                this.invalidate();
            }
        }
    }

    public void setContent(View v) {
        if (this.mContent != null) {
            this.removeView(this.mContent);
        }

        this.mContent = v;
        this.addView(this.mContent);
    }

    public View getContent() {
        return this.mContent;
    }

    public void setCustomViewBehind(MyCustomViewBehind cvb) {
        mViewBehind = cvb;
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int width = getDefaultSize(0, widthMeasureSpec);
        int height = getDefaultSize(0, heightMeasureSpec);
        this.setMeasuredDimension(width, height);
        int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width);
        int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
        this.mContent.measure(contentWidth, contentHeight);
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (w != oldw) {
            this.completeScroll();
            this.scrollTo(this.getDestScrollX(this.mCurItem), this.getScrollY());
        }

    }

    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int width = r - l;
        int height = b - t;
        this.mContent.layout(0, 0, width, height);
    }

    public void setAboveOffset(int i) {
        this.mContent.setPadding(i, this.mContent.getPaddingTop(), this.mContent.getPaddingRight(), this.mContent.getPaddingBottom());
    }

    public void computeScroll() {
        if (!this.mScroller.isFinished() && this.mScroller.computeScrollOffset()) {
            int oldX = this.getScrollX();
            int oldY = this.getScrollY();
            int x = this.mScroller.getCurrX();
            int y = this.mScroller.getCurrY();
            if (oldX != x || oldY != y) {
                this.scrollTo(x, y);
                this.pageScrolled(x);
            }

            this.invalidate();
        } else {
            this.completeScroll();
        }
    }

    private void pageScrolled(int xpos) {
        int widthWithMargin = this.getWidth();
        int position = xpos / widthWithMargin;
        int offsetPixels = xpos % widthWithMargin;
        float offset = (float) offsetPixels / (float) widthWithMargin;
        this.onPageScrolled(position, offset, offsetPixels);
    }

    protected void onPageScrolled(int position, float offset, int offsetPixels) {
        if (this.mOnPageChangeListener != null) {
            this.mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
        }

        if (this.mInternalPageChangeListener != null) {
            this.mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
        }

    }

    private void completeScroll() {
        boolean needPopulate = this.mScrolling;
        if (needPopulate) {
            this.setScrollingCacheEnabled(false);
            this.mScroller.abortAnimation();
            int oldX = this.getScrollX();
            int oldY = this.getScrollY();
            int x = this.mScroller.getCurrX();
            int y = this.mScroller.getCurrY();
            if (oldX != x || oldY != y) {
                this.scrollTo(x, y);
            }

            if (this.isMenuOpen()) {
                if (this.mOpenedListener != null) {
                    this.mOpenedListener.onOpened();
                }
            } else if (this.mClosedListener != null) {
                this.mClosedListener.onClosed();
            }
        }

        this.mScrolling = false;
    }

    public void setTouchMode(int i) {
        this.mTouchMode = i;
    }

    public int getTouchMode() {
        return this.mTouchMode;
    }

    private boolean thisTouchAllowed(MotionEvent ev) {
        int x = (int) (ev.getX() + this.mScrollX);
        if (this.isMenuOpen()) {
            return this.mViewBehind.menuOpenTouchAllowed(this.mContent, this.mCurItem, (float) x);
        } else {
            switch (this.mTouchMode) {
                case 0:
                    return this.mViewBehind.marginTouchAllowed(this.mContent, x);
                case 1:
                    return !this.isInIgnoredView(ev);
                case 2:
                    return false;
                default:
                    return false;
            }
        }
    }

    private boolean thisSlideAllowed(float dx) {
        boolean allowed = false;
        if (this.isMenuOpen()) {
            allowed = this.mViewBehind.menuOpenSlideAllowed(dx);
        } else {
            allowed = this.mViewBehind.menuClosedSlideAllowed(dx);
        }

        return allowed;
    }

    private int getPointerIndex(MotionEvent ev, int id) {
        int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id);
        if (activePointerIndex == -1) {
            this.mActivePointerId = -1;
        }

        return activePointerIndex;
    }

    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (!this.mEnabled) {
            return false;
        } else {
            int action = ev.getAction() & 255;
            if (action != 3 && action != 1 && (action == 0 || !this.mIsUnableToDrag)) {
                switch (action) {
                    case 0:
                        int index = MotionEventCompat.getActionIndex(ev);
                        this.mActivePointerId = MotionEventCompat.getPointerId(ev, index);
                        if (this.mActivePointerId != -1) {
                            this.mLastMotionX = this.mInitialMotionX = MotionEventCompat.getX(ev, index);
                            this.mLastMotionY = MotionEventCompat.getY(ev, index);
                            if (this.thisTouchAllowed(ev)) {
                                this.mIsBeingDragged = false;
                                this.mIsUnableToDrag = false;
                                if (this.isMenuOpen() && this.mViewBehind.menuTouchInQuickReturn(this.mContent, this.mCurItem, ev.getX() + this.mScrollX)) {
                                    this.mQuickReturn = true;
                                }
                            } else {
                                this.mIsUnableToDrag = true;
                            }
                        }
                    case 1:
                    case 3:
                    case 4:
                    case 5:
                    default:
                        break;
                    case 2:
                        this.determineDrag(ev);
                        break;
                    case 6:
                        this.onSecondaryPointerUp(ev);
                }

                if (!this.mIsBeingDragged) {
                    if (this.mVelocityTracker == null) {
                        this.mVelocityTracker = VelocityTracker.obtain();
                    }

                    this.mVelocityTracker.addMovement(ev);
                }

                return this.mIsBeingDragged || this.mQuickReturn;
            } else {
                this.endDrag();
                return false;
            }
        }
    }

    public boolean onTouchEvent(MotionEvent ev) {
        if (!this.mEnabled) {
            return false;
        } else if (!this.mIsBeingDragged && !this.thisTouchAllowed(ev)) {
            return false;
        } else {
            int action = ev.getAction();
            if (this.mVelocityTracker == null) {
                this.mVelocityTracker = VelocityTracker.obtain();
            }

            this.mVelocityTracker.addMovement(ev);
            int pointerIndex;
            float pageOffset;
            float x;
            switch (action & 255) {
                case 0:
                    this.completeScroll();
                    int index = MotionEventCompat.getActionIndex(ev);
                    this.mActivePointerId = MotionEventCompat.getPointerId(ev, index);
                    this.mLastMotionX = this.mInitialMotionX = ev.getX();
                    break;
                case 1:
                    if (this.mIsBeingDragged) {
                        VelocityTracker pointerIndex1 = this.mVelocityTracker;
                        pointerIndex1.computeCurrentVelocity(1000, (float) this.mMaximumVelocity);
                        int initialVelocity1 = (int) VelocityTrackerCompat.getXVelocity(pointerIndex1, this.mActivePointerId);
                        int scrollX1 = this.getScrollX();
                        pageOffset = (float) (scrollX1 - this.getDestScrollX(this.mCurItem)) / (float) this.getBehindWidth();
                        int activePointerIndex1 = this.getPointerIndex(ev, this.mActivePointerId);
                        if (this.mActivePointerId != -1) {
                            x = MotionEventCompat.getX(ev, activePointerIndex1);
                            int totalDelta1 = (int) (x - this.mInitialMotionX);
                            int nextPage = this.determineTargetPage(pageOffset, initialVelocity1, totalDelta1);
                            this.setCurrentItemInternal(nextPage, true, true, initialVelocity1);
                        } else {
                            this.setCurrentItemInternal(this.mCurItem, true, true, initialVelocity1);
                        }

                        this.mActivePointerId = -1;
                        this.endDrag();
                    } else if (this.mQuickReturn && this.mViewBehind.menuTouchInQuickReturn(this.mContent, this.mCurItem, ev.getX() + this.mScrollX)) {
                        this.setCurrentItem(1);
                        this.endDrag();
                    }
                    break;
                case 2:
                    if (!this.mIsBeingDragged) {
                        this.determineDrag(ev);
                        if (this.mIsUnableToDrag) {
                            return false;
                        }
                    }

                    if (this.mIsBeingDragged) {
                        pointerIndex = this.getPointerIndex(ev, this.mActivePointerId);
                        if (this.mActivePointerId != -1) {
                            float initialVelocity = MotionEventCompat.getX(ev, pointerIndex);
                            float scrollX = this.mLastMotionX - initialVelocity;
                            this.mLastMotionX = initialVelocity;
                            pageOffset = (float) this.getScrollX();
                            float activePointerIndex = pageOffset + scrollX;
                            x = (float) this.getLeftBound();
                            float totalDelta = (float) this.getRightBound();
                            if (activePointerIndex < x) {
                                activePointerIndex = x;
                            } else if (activePointerIndex > totalDelta) {
                                activePointerIndex = totalDelta;
                            }

                            this.mLastMotionX += activePointerIndex - (float) ((int) activePointerIndex);
                            this.scrollTo((int) activePointerIndex, this.getScrollY());
                            this.pageScrolled((int) activePointerIndex);
                        }
                    }
                    break;
                case 3:
                    if (this.mIsBeingDragged) {
                        this.setCurrentItemInternal(this.mCurItem, true, true);
                        this.mActivePointerId = -1;
                        this.endDrag();
                    }
                case 4:
                default:
                    break;
                case 5:
                    pointerIndex = MotionEventCompat.getActionIndex(ev);
                    this.mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
                    this.mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
                    break;
                case 6:
                    this.onSecondaryPointerUp(ev);
                    pointerIndex = this.getPointerIndex(ev, this.mActivePointerId);
                    if (this.mActivePointerId != -1) {
                        this.mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
                    }
            }

            return true;
        }
    }

    private void determineDrag(MotionEvent ev) {
        int activePointerId = this.mActivePointerId;
        int pointerIndex = this.getPointerIndex(ev, activePointerId);
        if (activePointerId != -1) {
            float x = MotionEventCompat.getX(ev, pointerIndex);
            float dx = x - this.mLastMotionX;
            float xDiff = Math.abs(dx);
            float y = MotionEventCompat.getY(ev, pointerIndex);
            float dy = y - this.mLastMotionY;
            float yDiff = Math.abs(dy);
            if (xDiff > (float) (this.isMenuOpen() ? this.mTouchSlop / 2 : this.mTouchSlop) && xDiff > yDiff && this.thisSlideAllowed(dx)) {
                this.startDrag();
                this.mLastMotionX = x;
                this.mLastMotionY = y;
                this.setScrollingCacheEnabled(true);
            } else if (xDiff > (float) this.mTouchSlop) {
                this.mIsUnableToDrag = true;
            }

        }
    }

    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
        this.mScrollX = (float) x;
        if (this.mEnabled) {
            this.mViewBehind.scrollBehindTo(this.mContent, x, y);
        }

        ((MySlidingMenu) this.getParent()).manageLayers(this.getPercentOpen());
    }

    private int determineTargetPage(float pageOffset, int velocity, int deltaX) {
        int targetPage = this.mCurItem;
        if (Math.abs(deltaX) > this.mFlingDistance && Math.abs(velocity) > this.mMinimumVelocity) {
            if (velocity > 0 && deltaX > 0) {
                --targetPage;
            } else if (velocity < 0 && deltaX < 0) {
                ++targetPage;
            }
        } else {
            targetPage = Math.round((float) this.mCurItem + pageOffset);
        }

        return targetPage;
    }

    protected float getPercentOpen() {
        return Math.abs(this.mScrollX - (float) this.mContent.getLeft()) / (float) this.getBehindWidth();
    }

    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        this.mViewBehind.drawShadow(this.mContent, canvas);
        this.mViewBehind.drawFade(this.mContent, canvas, this.getPercentOpen());
        this.mViewBehind.drawOffsetFade(mContent, canvas, getPercentOpen());
        this.mViewBehind.drawSelector(this.mContent, canvas, this.getPercentOpen());
    }

    private void onSecondaryPointerUp(MotionEvent ev) {
        int pointerIndex = MotionEventCompat.getActionIndex(ev);
        int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == this.mActivePointerId) {
            int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            this.mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
            this.mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            if (this.mVelocityTracker != null) {
                this.mVelocityTracker.clear();
            }
        }

    }

    private void startDrag() {
        this.mIsBeingDragged = true;
        this.mQuickReturn = false;
    }

    private void endDrag() {
        this.mQuickReturn = false;
        this.mIsBeingDragged = false;
        this.mIsUnableToDrag = false;
        this.mActivePointerId = -1;
        if (this.mVelocityTracker != null) {
            this.mVelocityTracker.recycle();
            this.mVelocityTracker = null;
        }

    }

    private void setScrollingCacheEnabled(boolean enabled) {
        if (this.mScrollingCacheEnabled != enabled) {
            this.mScrollingCacheEnabled = enabled;
        }

    }

    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if (v instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) v;
            int scrollX = v.getScrollX();
            int scrollY = v.getScrollY();
            int count = group.getChildCount();

            for (int i = count - 1; i >= 0; --i) {
                View child = group.getChildAt(i);
                if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && this.canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
                    return true;
                }
            }
        }

        return checkV && ViewCompat.canScrollHorizontally(v, -dx);
    }

    public boolean dispatchKeyEvent(KeyEvent event) {
        return super.dispatchKeyEvent(event) || this.executeKeyEvent(event);
    }

    public boolean executeKeyEvent(KeyEvent event) {
        boolean handled = false;
        if (event.getAction() == 0) {
            switch (event.getKeyCode()) {
                case 21:
                    handled = this.arrowScroll(17);
                    break;
                case 22:
                    handled = this.arrowScroll(66);
                    break;
                case 61:
                    if (Build.VERSION.SDK_INT >= 11) {
                        if (KeyEventCompat.hasNoModifiers(event)) {
                            handled = this.arrowScroll(2);
                        } else if (KeyEventCompat.hasModifiers(event, 1)) {
                            handled = this.arrowScroll(1);
                        }
                    }
            }
        }

        return handled;
    }

    public boolean arrowScroll(int direction) {
        View currentFocused = this.findFocus();
        if (currentFocused == this) {
            currentFocused = null;
        }

        boolean handled = false;
        View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
        if (nextFocused != null && nextFocused != currentFocused) {
            if (direction == 17) {
                handled = nextFocused.requestFocus();
            } else if (direction == 66) {
                if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
                    handled = this.pageRight();
                } else {
                    handled = nextFocused.requestFocus();
                }
            }
        } else if (direction != 17 && direction != 1) {
            if (direction == 66 || direction == 2) {
                handled = this.pageRight();
            }
        } else {
            handled = this.pageLeft();
        }

        if (handled) {
            this.playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
        }

        return handled;
    }

    boolean pageLeft() {
        if (this.mCurItem > 0) {
            this.setCurrentItem(this.mCurItem - 1, true);
            return true;
        } else {
            return false;
        }
    }

    boolean pageRight() {
        if (this.mCurItem < 1) {
            this.setCurrentItem(this.mCurItem + 1, true);
            return true;
        } else {
            return false;
        }
    }

    public interface OnPageChangeListener {
        void onPageScrolled(int var1, float var2, int var3);

        void onPageSelected(int var1);
    }

    public static class SimpleOnPageChangeListener implements MyCustomViewAbove.OnPageChangeListener {
        public SimpleOnPageChangeListener() {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
        }

        public void onPageScrollStateChanged(int state) {
        }
    }
}
